<template>
  <div class="ts-settings">
    <ts-header title="设置" back></ts-header>
    <ts-group class="ts-settings-menu">
      <ts-cell title="关于我们" link="/aboutUs"></ts-cell>
      <!--<ts-cell title="分享APP" isLink mode="edit" @click="shareVisible=true"></ts-cell>-->
      <ts-cell title="修改密码" link="/modifyPwd"></ts-cell>
      <ts-cell title="意见反馈" link="/feedback"></ts-cell>
      <ts-cell title="清除缓存" @click="clearCache"></ts-cell>
      <a style="overflow: hidden" href="tel:010-60844544"><ts-cell title="联系客服" link=""></ts-cell></a>
    </ts-group>
    <div class="logout">
      <ts-button type="primary" size="large" @click="logout">退出登录</ts-button>
    </div>
    <share :shareVisible.sync="shareVisible"></share>
  </div>
</template>
<script>
  import {LOGOUT} from '../../assets/js/api'
  import share from '../../components/common/share.vue'

  export default {
    name: 'settings',
    components: {
      share
    },
    data() {
      return {
        shareVisible: false
      }
    },
    async created(){
    },
    methods: {
      logout() {
        this.$modal({message: '你确认要退出吗？',lock: true}).then(async action => {
          let json = await this.$http.post(LOGOUT);
          if (json.result === 1) {
            this.$store.commit('LOGOUT');
            this.$router.replace('/login');
            location.reload()
            //退出登录之后解绑极光别名
            if($prod){
              await window.JPush.deleteAlias({ sequence: 1 },
                (result) => {
                  let sequence = result.sequence
                }, (error) => {
                  let sequence = error.sequence
                  let errorCode = error.code
                })
            }
          }
        })
      },
      clearCache() {
        if ($prod) {
          const vm = this;
          window.CacheClear(success => {
            vm.$modal.alert({message: '清除成功'});
          }, error => {
            vm.$modal.alert({message: '清除失败'});
          });
        }
      }
    }
  }
</script>

<style>
  .logout {
    padding: 1.20rem .36rem 0;
  }
</style>
